<template>
	<view>
		<view class="box">
			<view class="sections">
				<view class="tit">
					账号
				</view>
				<view class="inp">
					<input type="text" value="" v-model="phone" placeholder="请输入手机号"  placeholder-style="color:#AAAAAA" />
				</view>
			</view>
			<view class="sections">
				<view class="tit">
					验证码
				</view>
				<view class="inp">
					<input type="number" style="width: 60%;" value="" v-model="code" placeholder="请输入验证码" placeholder-style="color:#AAAAAA"  />
					<!-- <button class="yzm-box" :disabled="reSend" :style="{ color: yzmColor.color }" >{{ codeMsg }}</button> -->
					<text class="yzm-box" @click="getCode" v-if="!reSend">{{ codeMsg }}</text>
					<text class="yzm-box" style="color: #cccccc;" v-else>{{ codeMsg }}</text>
				</view>
			</view>
			<view class="sections">
				<view class="tit">
					新密码
				</view>
				<view class="inp">
					<input type="password" value="" v-model="pwd" placeholder="请输入新密码" placeholder-style="color:#AAAAAA" />
				</view>
			</view>
			<view class="sections">
				<view class="tit">
					再次输入新密码
				</view>
				<view class="inp">
					<input type="password" value="" v-model="rePwd" placeholder="请再次输入新密码" placeholder-style="color:#AAAAAA" />
				</view>
			</view>
			<view class="sub" @click="submit">
				确定
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone:'',
				pwd:'',
				rePwd:'',
				reSend: false,
				codeMsg: '获取验证码',
				codeTime: 0,
				code: '',
				yzmColor: {
					color: '#21E6C1',
					brgd: '#429FB0'
				},
			}
		},
		onLoad() {
			this.phone = uni.getStorageSync('userInfo').phone
		},
		methods: {
			getCode() {
				let that = this;
				that.countdown();
				that.$api
					.getCode({
						phone: that.phone,
						register: 3
					})
					.then(res => {
						if (res.data.code == 1) {
							that.$tools.msg(res.data.msg);
							// that.code = res.data.data.code;
						}
					})
					.catch(err => {
						console.log(err);
					});
				// that.code = '1234'
			},
			countdown() {
				let nsecond = 60;
				let that = this;
				let appCount = setInterval(function() {
					nsecond -= 1;
					that.codeTime = nsecond;
					if (nsecond == 0) {
						that.codeMsg = '重新获取';
						that.yzmColor.color = '#ffffff';
						that.yzmColor.brgd = '#429FB0';
						that.reSend = false;
						clearInterval(appCount);
					} else {
						that.codeMsg = '重新获取' + nsecond + 's';
						that.yzmColor.color = '#999999';
						that.yzmColor.brgd = '#cccccc';
						that.reSend = true;
					}
				}, 1000);
			},
			submit(){
				let that = this
				if(!that.code){
					that.$tools.msg('请先获取验证码')
					return false
				}
				if(!that.pwd){
					that.$tools.msg('密码不能为空')
					return false
				}
				if(that.pwd != that.rePwd){
					that.$tools.msg('两次密码不一致')
					return false
				}
				that.$api.editPwd({
					phone:that.phone,
					pwd_a:that.pwd,
					pwd_b:that.rePwd,
					code:that.code
				}).then(res=>{
					if(res.data.code==1){
						that.$tools.msg(res.data.msg)
						uni.clearStorageSync()
						setTimeout(()=>{
							uni.reLaunch({
								url:'../login/login'
							})
						},1000)
					}else{
						uni.showToast({
							icon:'none',
							title:res.data.msg
						})
						// this.$tools.msg(res.msg)
					}
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	page{
		background: #FFFFFF;
	}
	.box{
		width: 680upx;
		padding:60upx 35upx;
		display: flex;
		flex-direction: column;
		.sections{
			width: 100%;
			display: flex;
			flex-direction: column;
			padding-bottom: 60upx;
			.tit{
				width: 100%;
				font-size: 24upx;
				color: #333333;
			}
			.inp{
				width: 100%;
				border-bottom: 1upx solid #E6E6E6;
				display: flex;
				flex-direction: row;
				input{
					width: 100%;
					font-size: 24upx;
					padding: 30upx 0 10upx;
				}
				.yzm-box{
					width: 40%;
					font-size: 24upx;
					color: #21E6C1;
					line-height: 72upx;
					text-align: right;
				}
			}
		}
		.sub{
			width: 100%;
			height: 100upx;
			background: #21E6C1;
			font-size: 32upx;
			font-weight: bold;
			color: #FFFFFF;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 5upx;
		}
	}

</style>
